package com.ruoyi.tsjData.service.impl;

import com.deepoove.poi.data.PictureRenderData;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.*;
import com.ruoyi.task.domain.entity.DataTaskEntity;
import com.ruoyi.task.service.IDataTaskService;
import com.ruoyi.tsjData.domain.pad.TshjTaskReqDTO;
import com.ruoyi.tsjData.domain.pad.TshjTaskRespDTO;
import com.ruoyi.tsjData.domain.pad.TshjTreeDataItemDto;
import com.ruoyi.tsjData.domain.plat.*;
import com.ruoyi.tsjData.domain.result.*;
import com.ruoyi.tsjData.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

/**
 * 测试任务Service业务层处理
 */
@Service
public class DataTshjServiceImpl implements IDataTshjService {

    @Autowired
    private IDataTshjHjService dataTshjHjService;

    @Autowired
    private IDataTshjHjResultService dataTshjHjResultService;

    @Autowired
    private IDataTshjSdService dataTshjSdService;

    @Autowired
    private IDataTshjSdResultService dataTshjSdResultService;

    @Autowired
    private IDataTshjPbService dataTshjPbService;

    @Autowired
    private IDataTshjPbResultService dataTshjPbResultService;

    @Autowired
    private IDataTshjTyxnService dataTshjTyxnService;

    @Autowired
    private IDataTshjTyxnResultService dataTshjTyxnResultService;

    @Autowired
    private IDataTshjWshService dataTshjWshService;

    @Autowired
    private IDataTshjWshResultService dataTshjWshResultService;

    @Autowired
    private IDataTshjYyResultService dataTshjYyResultService;

    @Autowired
    private IDataTshjYyService dataTshjYyService;

    @Autowired
    private IDataTshjJxResultService dataTshjJxResultService;

    @Autowired
    private IDataTshjJxService dataTshjJxService;

    @Autowired
    private IDataTshjZhdService dataTshjZhdService;

    @Autowired
    private IDataTshjZhdResultService dataTshjZhdResultService;

    @Autowired
    private IDataTshjZhdlService dataTshjZhdlService;

    @Autowired
    private IDataTshjZhdlResultService dataTshjZhdlResultService;

    @Autowired
    private IDataTshjKxchService dataTshjKxchService;

    @Autowired
    private IDataTshjKxchResultService dataTshjKxchResultService;

    @Autowired
    private IDataTaskService dataTaskService;

    @Autowired
    private IDataTshjResultService dataTshjResultService;

    @Autowired
    private IDataTshjJchmjService jchmjService;

    @Autowired
    private IDataTshjJchmjResultService jchmjResultService;

    @Autowired
    private IDataTshjLylService lylService;

    @Autowired
    private IDataTshjLylResultService lylResultService;

    @Autowired
    private IDataTshjZhdoService zhdoService;

    @Autowired
    private IDataTshjZhdoResultService zhdoResultService;

    @Autowired
    private IDataTshjZhduService zhduService;

    @Autowired
    private IDataTshjZhduResultService zhduResultService;

    @Autowired
    private IDataTshjZshService zshService;

    @Autowired
    private IDataTshjZshResultService zshResultService;

    /**
     * 根据任务编号获取提升机测试数据
     * @return
     */
    @Override
    public TshjTaskReqDTO getDetailTshj(Long dataTaskId) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        //测试数据基本信息
        Future<DataTaskEntity> taskFuture = dataTaskService.selectDataTask(dataTaskId);
        //环境
        Future<List<DataTshjHj>> hjListFuture = dataTshjHjService.selectDataHjById(dataTaskId);
        //间隙
        Future<List<DataTshjJx>> jxListFuture = dataTshjJxService.selectJx(dataTaskId);
        //空行程
        Future<List<DataTshjKxch>> kxchListFuture = dataTshjKxchService.selectKxch(dataTaskId);
        //偏摆
        Future<List<DataTshjPb>> pbListFuture = dataTshjPbService.selectPb(dataTaskId);
        //速度
        Future<List<DataTshjSd>> sdListFuture = dataTshjSdService.selectSd(dataTaskId);
        //调压性能
        Future<List<DataTshjTyxn>> tyxnListFuture = dataTshjTyxnService.selectTyxn(dataTaskId);
        //温升
        Future<List<DataTshjWsh>> wshListFuture = dataTshjWshService.selectWsh(dataTaskId);
        //油压
        Future<List<DataTshjYy>> yyListFuture = dataTshjYyService.selectYy(dataTaskId);
        //制动力
        Future<List<DataTshjZhdl>> zhdlListFuture = dataTshjZhdlService.selectZhdl(dataTaskId);
        //制动
        Future<List<DataTshjZhd>> zhdListFuture = dataTshjZhdService.selectZhd(dataTaskId);
        //接触面积
        Future<List<DataTshjJchmj>> jchmjListFuture = jchmjService.selectDataTshjJchmjByDataTaskId(dataTaskId);
        //拉压力
        Future<List<DataTshjLyl>> lylListFuture = lylService.selectDataTshjLylByDataTaskId(dataTaskId);
        //振动
        Future<List<DataTshjZhdo>> zhdoListFuture = zhdoService.selectDataTshjZhdoByDataTaskId(dataTaskId);
        //照度
        Future<List<DataTshjZhdu>> zhduListFuture = zhduService.selectDataTshjZhduByDataTaskId(dataTaskId);
        //噪声
        Future<List<DataTshjZsh>> zshListFuture = zshService.selectDataTshjZshByDataTaskId(dataTaskId);
        //添加到集合对象中
        List<Future<?>> futureList = new ArrayList<>();
        futureList.add(taskFuture);
        futureList.add(hjListFuture);
        futureList.add(jxListFuture);
        futureList.add(kxchListFuture);
        futureList.add(pbListFuture);
        futureList.add(sdListFuture);
        futureList.add(tyxnListFuture);
        futureList.add(wshListFuture);
        futureList.add(yyListFuture);
        futureList.add(zhdlListFuture);
        futureList.add(zhdListFuture);
        futureList.add(jchmjListFuture);
        futureList.add(lylListFuture);
        futureList.add(zhdoListFuture);
        futureList.add(zhduListFuture);
        futureList.add(zshListFuture);
        // 从future提取所有数据
        TshjTaskRespDTO tshjTaskRespDTO = new TshjTaskRespDTO();
        for (Future<?> future : futureList) {
            while (true) {
                if (taskFuture.isDone() && !taskFuture.isCancelled()) {
                    // 获取结果
                    Object resultObject = future.get();
                    // 任务数据
                    if (resultObject instanceof DataTaskEntity) {
                        tshjTaskRespDTO.setDataTaskEntity((DataTaskEntity) resultObject);
                    }
                    if (resultObject instanceof java.util.List) {
                        List<Object> resultList = (List<Object>) resultObject;
                        if (!resultList.isEmpty()) {
                            Object item = resultList.get(0);
                            //测试任务类型获取数据
                            if (item instanceof DataTshjHj) {
                                tshjTaskRespDTO.setHjTestList(ListUtils.castList(resultList, DataTshjHj.class));
                            }
                            if (item instanceof DataTshjJx) {
                                tshjTaskRespDTO.setJxTestList(ListUtils.castList(resultList, DataTshjJx.class));
                            }
                            if (item instanceof DataTshjKxch) {
                                tshjTaskRespDTO.setKxchTestList(ListUtils.castList(resultList, DataTshjKxch.class));
                            }
                            if (item instanceof DataTshjPb) {
                                tshjTaskRespDTO.setPbTestList(ListUtils.castList(resultList, DataTshjPb.class));
                            }
                            if (item instanceof DataTshjSd) {
                                tshjTaskRespDTO.setSdTestList(ListUtils.castList(resultList, DataTshjSd.class));
                            }
                            if (item instanceof DataTshjTyxn) {
                                tshjTaskRespDTO.setTyxnTestList(ListUtils.castList(resultList, DataTshjTyxn.class));
                            }
                            if (item instanceof DataTshjWsh) {
                                tshjTaskRespDTO.setWshTestList(ListUtils.castList(resultList, DataTshjWsh.class));
                            }
                            if (item instanceof DataTshjYy) {
                                tshjTaskRespDTO.setYyTestList(ListUtils.castList(resultList, DataTshjYy.class));
                            }
                            if (item instanceof DataTshjZhd) {
                                tshjTaskRespDTO.setZhdTestList(ListUtils.castList(resultList, DataTshjZhd.class));
                            }
                            if (item instanceof DataTshjZhdl) {
                                tshjTaskRespDTO.setZhdlTestList(ListUtils.castList(resultList, DataTshjZhdl.class));
                            }
                            if (item instanceof DataTshjJchmj) {
                                tshjTaskRespDTO.setJchmjEntityList(ListUtils.castList(resultList, DataTshjJchmj.class));
                            }
                            if (item instanceof DataTshjLyl) {
                                tshjTaskRespDTO.setLylEntityList(ListUtils.castList(resultList, DataTshjLyl.class));
                            }
                            if (item instanceof DataTshjZhdo) {
                                tshjTaskRespDTO.setZhdoEntityList(ListUtils.castList(resultList, DataTshjZhdo.class));
                            }
                            if (item instanceof DataTshjZhdu) {
                                tshjTaskRespDTO.setZhduEntityList(ListUtils.castList(resultList, DataTshjZhdu.class));
                            }
                            if (item instanceof DataTshjZsh) {
                                tshjTaskRespDTO.setZshEntityList(ListUtils.castList(resultList, DataTshjZsh.class));
                            }
                        }
                    }
                    break;
                } else {
                    // 轮询查询结果
                    Thread.sleep(10);
                }
            }
        }
        //数据排序处理,间隙和空行程数据根据闸序号
        List<DataTshjJx> dataTshjJxList = tshjTaskRespDTO.getJxTestList();
        if (null != dataTshjJxList && !dataTshjJxList.isEmpty()) {
            Map<String, List<DataTshjJx>> dataTshjJxMap = dataTshjJxList.stream().collect(Collectors.groupingBy(DataTshjJx::getZhaIndex));
            tshjTaskRespDTO.setJxTestMap(dataTshjJxMap);
        }
        List<DataTshjKxch> dataTshjKxchList = tshjTaskRespDTO.getKxchTestList();
        if (null != dataTshjKxchList && !dataTshjKxchList.isEmpty()) {
            Map<String, List<DataTshjKxch>> dataTshjKxchMap = dataTshjKxchList.stream().collect(Collectors.groupingBy(DataTshjKxch::getZhaIndex));
            tshjTaskRespDTO.setKxchTestMap(dataTshjKxchMap);
        }
        //速度根据提人提物加上提下放分组
        List<DataTshjSd> dataTshjSdList = tshjTaskRespDTO.getSdTestList();
        if (null != dataTshjKxchList && !dataTshjKxchList.isEmpty()) {
            Map<String, Map<String,List<DataTshjSd>>> dataTshjSdMap = dataTshjSdList.stream().collect(Collectors.groupingBy(DataTshjSd::getUp, Collectors.groupingBy(DataTshjSd::getUpRen)));
            tshjTaskRespDTO.setSdTestMap(dataTshjSdMap);
        }
        //调压根据一号二号液压站电压电流分组
        List<DataTshjTyxn> dataTshjTyxnList = tshjTaskRespDTO.getTyxnTestList();
        if (null != dataTshjTyxnList && !dataTshjTyxnList.isEmpty()) {
            Map<String, Map<String,List<DataTshjTyxn>>> dataTshjTyxnMap = dataTshjTyxnList.stream().collect(Collectors.groupingBy(DataTshjTyxn::getYyzh, Collectors.groupingBy(DataTshjTyxn::getZhadl)));
            tshjTaskRespDTO.setTyxnTestMap(dataTshjTyxnMap);
        }
        //油压根据一号二号液压站分组
        List<DataTshjYy> dataTshjYyList = tshjTaskRespDTO.getYyTestList();
        if (null != dataTshjYyList && !dataTshjYyList.isEmpty()) {
            Map<String,List<DataTshjYy>> dataTshjYyMap = dataTshjYyList.stream().collect(Collectors.groupingBy(DataTshjYy::getYyzh));
            tshjTaskRespDTO.setYyTestMap(dataTshjYyMap);
        }
        //制动根据上提下放分组
        List<DataTshjZhd> dataTshjZhdList = tshjTaskRespDTO.getZhdTestList();
        if (null != dataTshjZhdList && !dataTshjZhdList.isEmpty()) {
            Map<String,List<DataTshjZhd>> dataTshjZhdMap = dataTshjZhdList.stream().collect(Collectors.groupingBy(DataTshjZhd::getUp));
            tshjTaskRespDTO.setZhdTestMap(dataTshjZhdMap);
        }
        //目录结构拼接
        List<TshjTreeDataItemDto> treeDataList = new ArrayList<>();
        //速度测试
        if (null != tshjTaskRespDTO.getSdTestList() && !tshjTaskRespDTO.getSdTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("sdTestList");
            tshjTaskRespDTO.getSdTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getUp().equals("0") ?  item.getUpRen().equals("0") ? "下放物" : "下放人" : item.getUpRen().equals("0") ? "上提物" : "上提人")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("sdTestList");
            treeDataList.add(treeDataItemDto);
        }
        //偏摆测试
        if (null != tshjTaskRespDTO.getPbTestList() && !tshjTaskRespDTO.getPbTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("pbTestList");
            tshjTaskRespDTO.getPbTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getCshType().equals("0") ? "左偏摆": item.getCshType().equals("1") ? "右偏摆" : "左右偏摆")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("pbTestList");
            treeDataList.add(treeDataItemDto);
        }
        //油压测试
        if (null != tshjTaskRespDTO.getYyTestList() && !tshjTaskRespDTO.getYyTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("yyTestList");
            tshjTaskRespDTO.getYyTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getYyzh()+"号液压站")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("yyTestList");
            treeDataList.add(treeDataItemDto);
        }
        // 调压性能测试
        if (null != tshjTaskRespDTO.getTyxnTestList() && !tshjTaskRespDTO.getTyxnTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("tyxnTestList");
            tshjTaskRespDTO.getTyxnTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getYyzh()+"号液压站")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("tyxnTestList");
            treeDataList.add(treeDataItemDto);
        }
        // 温升测试
        if (null != tshjTaskRespDTO.getWshTestList() && !tshjTaskRespDTO.getWshTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("wshTestList");
            tshjTaskRespDTO.getWshTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("wshTestList");
            treeDataList.add(treeDataItemDto);
        }
        //间隙测试
        if (null != tshjTaskRespDTO.getJxTestList() && !tshjTaskRespDTO.getJxTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("jxTestList");
            tshjTaskRespDTO.getJxTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getZhaIndex()+"号闸")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("jxTestList");
            treeDataList.add(treeDataItemDto);
        }
        //制动测试
        if (null != tshjTaskRespDTO.getZhdTestList() && !tshjTaskRespDTO.getZhdTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhdTestList");
            tshjTaskRespDTO.getZhdTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getUp().equals("0") ?  item.getUpRen().equals("0") ? "下放物" : "下放人" : item.getUpRen().equals("0") ? "上提物" : "上提人")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhdTestList");
            treeDataList.add(treeDataItemDto);
        }
        //空行程测试
        if (null != tshjTaskRespDTO.getKxchTestList() && !tshjTaskRespDTO.getKxchTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("kxchTestList");
            tshjTaskRespDTO.getKxchTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), item.getZhaIndex()+"号闸")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("kxchTestList");
            treeDataList.add(treeDataItemDto);
        }
        //制动力测试
        if (null != tshjTaskRespDTO.getZhdlTestList() && !tshjTaskRespDTO.getZhdlTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhdlTestList");
            tshjTaskRespDTO.getZhdlTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhdlTestList");
            treeDataList.add(treeDataItemDto);
        }
        //环境测试
        if (null != tshjTaskRespDTO.getHjTestList() && !tshjTaskRespDTO.getHjTestList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("hjTestList");
            tshjTaskRespDTO.getHjTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("hjTestList");
            treeDataList.add(treeDataItemDto);
        }
        //拉压力测试
        if (null != tshjTaskRespDTO.getLylEntityList() && !tshjTaskRespDTO.getLylEntityList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("lylEntityList");
            tshjTaskRespDTO.getLylEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("lylEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //照度测试
        if (null != tshjTaskRespDTO.getZhduEntityList() && !tshjTaskRespDTO.getZhduEntityList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhduEntityList");
            tshjTaskRespDTO.getZhduEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhduEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //噪声测试
        if (null != tshjTaskRespDTO.getZshEntityList() && !tshjTaskRespDTO.getZshEntityList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zshEntityList");
            tshjTaskRespDTO.getZshEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zshEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //振动测试
        if (null != tshjTaskRespDTO.getZhdoEntityList() && !tshjTaskRespDTO.getZhdoEntityList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhdoEntityList");
            tshjTaskRespDTO.getZhdoEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("zhdoEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //接触面积测试
        if (null != tshjTaskRespDTO.getJchmjEntityList() && !tshjTaskRespDTO.getJchmjEntityList().isEmpty()) {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("jchmjEntityList");
            tshjTaskRespDTO.getJchmjEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new TshjTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            TshjTreeDataItemDto treeDataItemDto = new TshjTreeDataItemDto("jchmjEntityList");
            treeDataList.add(treeDataItemDto);
        }
        tshjTaskRespDTO.setTshjTreeDataList(treeDataList);
        System.out.printf("任务ID为 %d 的“提升机测试任务”查询耗时 %d。", dataTaskId, (System.currentTimeMillis() - startTime));
        return tshjTaskRespDTO;
    }

    /**
     * 变更数据
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDetailTshj(TshjTaskReqDTO tshjTaskReqDTO) {
        //测试任务
        DataTaskEntity dataTaskEntity = tshjTaskReqDTO.getDataTaskEntity();
        //环境数据
        List<DataTshjHj> hjTestList = tshjTaskReqDTO.getHjTestList();
        //间隙数据
        List<DataTshjJx> jxTestList = tshjTaskReqDTO.getJxTestList();
        //空行程数据
        List<DataTshjKxch> kxchTestList = tshjTaskReqDTO.getKxchTestList();
        //偏摆数据
        List<DataTshjPb> pbTestList = tshjTaskReqDTO.getPbTestList();
        //速度数据
        List<DataTshjSd> sdTestList = tshjTaskReqDTO.getSdTestList();
        //调压性能数据
        List<DataTshjTyxn> tyxnList = tshjTaskReqDTO.getTyxnTestList();
        //温升数据
        List<DataTshjWsh> wshList = tshjTaskReqDTO.getWshTestList();
        //油压数据
        List<DataTshjYy> yyTestList = tshjTaskReqDTO.getYyTestList();
        //制动力数据
        List<DataTshjZhdl> zhdlTestList = tshjTaskReqDTO.getZhdlTestList();
        //制动数据
        List<DataTshjZhd> zhdTestList = tshjTaskReqDTO.getZhdTestList();
        //更新测试任务数据
        dataTaskService.updateDataTask(dataTaskEntity);
        //更新环境任务数据
        dataTshjHjService.updateBatchDataTshjHj(hjTestList);
        //更新间隙任务数据
        dataTshjJxService.updateBatchDataTshjJx(jxTestList);
        //更新空行程任务数据
        dataTshjKxchService.updateBatchDataTshjKxch(kxchTestList);
        //更新偏摆任务数据
        dataTshjPbService.updateBatchDataTshjPb(pbTestList);
        //更新速度任务数据
        dataTshjSdService.updateBatchDataTshjSd(sdTestList);
        //更新调压性能任务数据
        dataTshjTyxnService.batchDataTshjTyxn(tyxnList);
        //更新温升任务数据
        dataTshjWshService.batchDataTshjWsh(wshList);
        //更新油压任务数据
        dataTshjYyService.updateBatchDataTshjYy(yyTestList);
        //更新制动力任务数据
        dataTshjZhdlService.updateBatchDataTshjZhdl(zhdlTestList);
        //更新制动任务数据
        dataTshjZhdService.updateBatchDataTshjZhd(zhdTestList);
        //变更接触面积数据
        //变更拉压力数据
        //变更振动数据
        //变更照度数据
        //变更噪声数据
        return 1;
    }

    /**
     * 删除提升机所有数据，变更数据状态为2
     * @param dataTaskId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delAllTsjData(Long[] dataTaskId) {
        //dataTaskId不为空
        if(null != dataTaskId && dataTaskId.length > 0) {
            //变更任务状态
            try {
                dataTaskService.deleteDataTaskByDataTaskIds(dataTaskId, "002");
            }catch (Exception e){
                e.printStackTrace();
            }
            //变更环境测试状态
            dataTshjHjService.updateDataTshjHjByDataTaskIds(dataTaskId);
            //变更间隙测试状态
            dataTshjJxService.updateDataTshjJxByDataTaskIds(dataTaskId);
            //变更空行程
            dataTshjKxchService.updateDataTshjKxchByDataTaskIds(dataTaskId);
            //变更偏摆
            dataTshjPbService.updateDataTshjPbByDataTaskIds(dataTaskId);
            //变更速度
            dataTshjSdService.updateDataTshjSdByDataTaskIds(dataTaskId);
            //变更调压性能
            dataTshjTyxnService.updateDataTshjTyxnByDataTaskIds(dataTaskId);
            //变更温升
            dataTshjWshService.updateDataTshjWshByDataTaskIds(dataTaskId);
            //变更油压
            dataTshjYyService.updateDataTshjYyByDataTaskIds(dataTaskId);
            //变更制动力
            dataTshjZhdlService.updateDataTshjZhdlByDataTaskIds(dataTaskId);
            //变更制动
            dataTshjZhdService.updateDataTshjZhdByDataTaskIds(dataTaskId);
            //变更接触面积数据
            jchmjService.updateDataTshjJchmjByDataTaskIds(dataTaskId);
            //变更拉压力数据
            lylService.updateDataTshjLylByDataTaskIds(dataTaskId);
            //变更振动数据
            zhdoService.updateDataTshjZhdoByDataTaskIds(dataTaskId);
            //变更照度数据
            zhduService.updateDataTshjZhduByDataTaskIds(dataTaskId);
            //变更噪声数据
            zshService.updateDataTshjZshByDataTaskIds(dataTaskId);
        }
        return 1;
    }

    /**
     * 提升机结果数据保存
     * @param dataTshjResult
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long dataTshjResult(DataTshjResult dataTshjResult) {
        Long resultId;
        //保存测试结果信息
        if( null != dataTshjResult.getDataTshjResultDetail()) {
            dataTshjResultService.insertDataTshjResult(dataTshjResult.getDataTshjResultDetail());
            resultId = dataTshjResult.getDataTshjResultDetail().getResultId();
        } else {
            resultId = 0L;
        }
        //保存环境结果
        if( null != dataTshjResult.getDataTshjHjResult() && !dataTshjResult.getDataTshjHjResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjHjResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjHjResultService.insertDataTshjHjResult(item);
            });
        }
        //保存间隙结果
        if(null != dataTshjResult.getDataTshjJxResult() && !dataTshjResult.getDataTshjJxResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjJxResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjJxResultService.insertDataTshjJxResult(item);
            });
        }
        //保存空行程结果
        if(null != dataTshjResult.getDataTshjKxchResult() && !dataTshjResult.getDataTshjKxchResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjKxchResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjKxchResultService.insertDataTshjKxchResult(item);
            });
        }
        //保存偏摆结果
        if(null != dataTshjResult.getDataTshjPbResult() && !dataTshjResult.getDataTshjPbResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjPbResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjPbResultService.insertDataTshjPbResult(item);
            });
        }
        //保存速度结果
        if(null != dataTshjResult.getDataTshjSdResult() && !dataTshjResult.getDataTshjSdResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjSdResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjSdResultService.insertDataTshjSdResult(item);
            });
        }
        //保存调压性能结果
        if(null != dataTshjResult.getDataTshjTyxnResult() && !dataTshjResult.getDataTshjTyxnResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjTyxnResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjTyxnResultService.insertDataTshjTyxnResult(item);
            });
        }
        //保存温升结果
        if(null != dataTshjResult.getDataTshjWshResult() && !dataTshjResult.getDataTshjWshResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjWshResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjWshResultService.insertDataTshjWshResult(item);
            });
        }
        //保存油压结果
        if(null != dataTshjResult.getDataTshjYyResult() && !dataTshjResult.getDataTshjYyResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjYyResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjYyResultService.insertDataTshjYyResult(item);
            });
        }
        //保存制动力结果
        if(null != dataTshjResult.getDataTshjZhdlResult() && !dataTshjResult.getDataTshjZhdlResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjZhdlResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjZhdlResultService.insertDataTshjZhdlResult(item);
            });
        }
        //保存制动结果
        if(null != dataTshjResult.getDataTshjZhdResult() && !dataTshjResult.getDataTshjZhdResult().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjZhdResult().forEach(item -> {
                item.setDataResultId(resultId);
                dataTshjZhdResultService.insertDataTshjZhdResult(item);
            });
        }
        //保存接触面积结果
        if(null != dataTshjResult.getDataTshjJchmjResults() && !dataTshjResult.getDataTshjJchmjResults().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjJchmjResults().forEach(item -> {
                item.setDataResultId(resultId);
                jchmjResultService.insertDataTshjJchmjResult(item);
            });
        }
        //保存拉压力结果
        if(null != dataTshjResult.getDataTshjLylResults() && !dataTshjResult.getDataTshjLylResults().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjLylResults().forEach(item -> {
                item.setDataResultId(resultId);
                lylResultService.insertDataTshjLylResult(item);
            });
        }
        //保存振动结果
        if(null != dataTshjResult.getDataTshjZhdoResults() && !dataTshjResult.getDataTshjZhdoResults().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjZhdoResults().forEach(item -> {
                item.setDataResultId(resultId);
                zhdoResultService.insertDataTshjZhdoResult(item);
            });
        }
        //保存照度结果
        if(null != dataTshjResult.getDataTshjZhduResults() && !dataTshjResult.getDataTshjZhduResults().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjZhduResults().forEach(item -> {
                item.setDataResultId(resultId);
                zhduResultService.insertDataTshjZhduResult(item);
            });
        }
        //保存噪声结果
        if(null != dataTshjResult.getDataTshjZshResults() && !dataTshjResult.getDataTshjZshResults().isEmpty() && resultId != 0L) {
            dataTshjResult.getDataTshjZshResults().forEach(item -> {
                item.setDataResultId(resultId);
                zshResultService.insertDataTshjZshResult(item);
            });
        }
        return resultId;
    }


    /**
     * 提升机保存结果导入报告
     */
    @Override
    public String dataTshjImportReport(DataTshjResult dataTshjResult) {
        // 报告模板名称
        String template = dataTshjResult.getTempId();
        Long res = 0L;
        //结果保存
        if(dataTshjResult.getDataTshjResultDetail().getResultId() == null) {
            res = dataTshjResult(dataTshjResult);
        }
        if(res != null) {
            //任务id
            Long dataTaskId = dataTshjResult.getDataTshjResultDetail().getDataTaskId();
            res = dataTshjResult.getDataTshjResultDetail().getResultId();
            //获取测试任务信息
            DataTaskEntity dataTaskEntity = dataTaskService.selectDataTaskByDataTaskId(dataTaskId);
            //获取环境保存结果
            List<DataTshjHjResult> dataTshjHjResults = dataTshjHjResultService.selectDataTshjHjResultByDataTaskId(dataTaskId, res);
            //间隙保存结果
            List<DataTshjJxResult> dataTshjJxResults = dataTshjJxResultService.selectDataTshjJxResultByDataTaskId(dataTaskId, res);
            //空行程保存结果
            List<DataTshjKxchResult> dataTshjKxchResults = dataTshjKxchResultService.selectDataTshjKxchResultByDataTaskId(dataTaskId, res);
            //偏摆保存结果
            List<DataTshjPbResult> dataTshjPbResults = dataTshjPbResultService.selectDataTshjPbResultByDataTaskId(dataTaskId, res);
            //速度保存结果
            List<DataTshjSdResult> dataTshjSdResults = dataTshjSdResultService.selectDataTshjSdResultByDataTaskId(dataTaskId, res);
            //调压性能结果
            List<DataTshjTyxnResult> dataTshjTyxnResults = dataTshjTyxnResultService.selectDataTshjTyxnResultByDataTaskId(dataTaskId, res);
            //温升结果
            List<DataTshjWshResult> dataTshjWshResults = dataTshjWshResultService.selectDataTshjWshResultByDataTaskId(dataTaskId, res);
            //油压结果
            List<DataTshjYyResult> dataTshjYyResults = dataTshjYyResultService.selectDataTshjYyResultByDataTaskId(dataTaskId, res);
            //制动力结果
            List<DataTshjZhdlResult> dataTshjZhdlResults = dataTshjZhdlResultService.selectDataTshjZhdlResultByDataTaskId(dataTaskId, res);
            //制动结果
            List<DataTshjZhdResult> dataTshjZhdResults = dataTshjZhdResultService.selectDataTshjZhdResultByDataTaskId(dataTaskId, res);
            //接触面积
            List<DataTshjJchmjResult> dataTshjJchmjResults = jchmjResultService.selectDataTshjJchmjResultByDataTaskId(dataTaskId, res);
            //拉压力
            List<DataTshjLylResult> dataTshjLylResults = lylResultService.selectDataTshjLylResultByDataTaskId(dataTaskId, res);
            //振动
            List<DataTshjZhdoResult> dataTshjZhdoResults = zhdoResultService.selectDataTshjZhdoResultByDataTaskId(dataTaskId, res);
            //照度
            List<DataTshjZhduResult> dataTshjZhduResults = zhduResultService.selectDataTshjZhduResultByDataTaskId(dataTaskId, res);
            //噪声
            List<DataTshjZshResult> dataTshjZshResults = zshResultService.selectDataTshjZshResultByDataTaskId(dataTaskId, res);
            //测试图数据
            String imgPath = RuoYiConfig.getProfile() + RuoYiConfig.getChartPath();
            // 大曲线图的长宽
            int picW = 450;
            int picH = 250;
            // 小曲线图的长款
            int picSW = 280;
            int picSH = 156;
            //导入报告中
            Map<String, Object> params = new HashMap<>();
            List<Map<String, Object>> jchmjList = new ArrayList<>();
            List<Map<String, Object>> lylList = new ArrayList<>();
            List<Map<String, Object>> zhdoList = new ArrayList<>();
            List<Map<String, Object>> zhduList = new ArrayList<>();
            List<Map<String, Object>> zshList = new ArrayList<>();
            DecimalFormat df3 = new DecimalFormat("####0.000");
            //基本检测信息
            if(null != dataTaskEntity) {
                params.put("受检单位", dataTaskEntity.getShjdw());
                params.put("设备名称", dataTaskEntity.getShbbh());
                params.put("主检姓名", dataTaskEntity.getZhjxm());
                params.put("测试人员", dataTaskEntity.getCshry());
                params.put("检测日期", DateUtils.dateTime(dataTaskEntity.getTaskCreateTime()));
            }
            //环境数据
            if(null != dataTshjHjResults && !dataTshjHjResults.isEmpty()) {
                params.put("测试时间", DateUtils.dateTime(dataTshjHjResults.get(0).getSaveTime()));
                params.put("温度", dataTshjHjResults.get(0).getWd());
                params.put("湿度", dataTshjHjResults.get(0).getShd());
                params.put("大气压", dataTshjHjResults.get(0).getDqy());
                if(StringUtils.equals("1", dataTshjHjResults.get(0).getShowJw())) {
                    params.put("甲烷浓度", dataTshjHjResults.get(0).getJwnd());
                }
                if(StringUtils.equals("1", dataTshjHjResults.get(0).getShowZhs())) {
                    params.put("转速", dataTshjHjResults.get(0).getZhs());
                }
            }
            // 间隙数据
            if (null != dataTshjJxResults && !dataTshjJxResults.isEmpty()) {
                for(DataTshjJxResult dataTshjJxResult : dataTshjJxResults) {
                    params.put(dataTshjJxResult.getZhaIndex() + "号闸左间隙", dataTshjJxResult.getJxLeftMax());
                    params.put(dataTshjJxResult.getZhaIndex() + "号闸右间隙", dataTshjJxResult.getJxRightMax());
                    params.put(dataTshjJxResult.getZhaIndex() + "号闸间隙曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(dataTshjJxResult.getWyImg(), "/profile/chartPath", imgPath)));
                }
            }
            //空行程数据
            if (null != dataTshjKxchResults && !dataTshjKxchResults.isEmpty()) {
                for(DataTshjKxchResult dataTshjKxchResult : dataTshjKxchResults) {
                    params.put(dataTshjKxchResult.getZhaIndex() + "号闸左时间", dataTshjKxchResult.getKxcLtime());
                    params.put(dataTshjKxchResult.getZhaIndex() + "号闸右时间", dataTshjKxchResult.getKxcRtime());
                }
            }
            // 偏摆数据
            if (null != dataTshjPbResults && !dataTshjPbResults.isEmpty()) {
                params.put("左偏摆", dataTshjPbResults.get(0).getPianbdLeft());
                params.put("右偏摆", dataTshjPbResults.get(0).getPianbdRight());
                params.put("偏摆曲线", new PictureRenderData(picW, picH, StringUtils.replace(dataTshjPbResults.get(0).getPdImg(), "/profile/chartPath", imgPath)));
            }
            // 速度数据
            if (null != dataTshjSdResults && !dataTshjSdResults.isEmpty()) {
                dataTshjSdResults.forEach(item -> {
                    //基本数据
                    if(null != item.getUp() && null != item.getUpRen()) {
                        String type = DictUtils.getDictLabel("tshj_sd_up", item.getUp(), "") + DictUtils.getDictLabel("tshj_sd_upren", item.getUpRen(), "");
                        params.put(type + "电流变比", item.getParaDlbb());
                        params.put(type + "提升距离", item.getParaTshjl());
                        params.put(type + "运行时间", item.getYxshj());
                        params.put(type + "最大速度", item.getSdMax());
                        params.put(type + "最大电流", item.getDlMax());
                        params.put(type + "转速", item.getZhuansu());
                        params.put(type + "加速度段平均加速度", item.getAccJia());
                        params.put(type + "减速度段平均减速度", item.getAccJian());
                    }
                    //上提人速度数据
                    if(StringUtils.equals("1", item.getUp()) && StringUtils.equals("1", item.getUpRen())) {
                        params.put("上提人速度电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddlupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提人速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddlupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提人电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getDlupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提人井深速度曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getJshsdupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提人加速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getJsdupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提人前40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getQ40ssdupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提人后40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getH40ssdupImg(), "/profile/chartPath", imgPath)));
                    }
                    //上提物速度数据
                    if(StringUtils.equals("1", item.getUp()) && StringUtils.equals("0", item.getUpRen())) {
                        params.put("上提物速度电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddlupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提物速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddlupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提物电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getDlupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提物井深速度曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getJshsdupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提物加速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getJsdupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提物前40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getQ40ssdupImg(), "/profile/chartPath", imgPath)));
                        params.put("上提物后40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getH40ssdupImg(), "/profile/chartPath", imgPath)));
                    }
                    //下放人速度数据
                    if(StringUtils.equals("0", item.getUp()) && StringUtils.equals("1", item.getUpRen())) {
                        params.put("下放人速度电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放人速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放人电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放人井深速度曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放人加速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放人前40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放人后40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                    }
                    //下放物速度数据
                    if(StringUtils.equals("0", item.getUp()) && StringUtils.equals("0", item.getUpRen())) {
                        params.put("下放物速度电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放物速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放物电流曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放物井深速度曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放物加速度曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放物前40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                        params.put("下放物后40s曲线", new PictureRenderData(picSW, picSH, StringUtils.replace(item.getSddldownImg(), "/profile/chartPath", imgPath)));
                    }
                });
            }
            //调压性能数据
            if (null != dataTshjTyxnResults && !dataTshjTyxnResults.isEmpty()) {
                for(DataTshjTyxnResult dataTshjTyxnResult : dataTshjTyxnResults) {
                    params.put(dataTshjTyxnResult.getYyzh() + "号一级油压", dataTshjTyxnResult.getYjyy());
                    params.put(dataTshjTyxnResult.getYyzh() + "号二级油压", dataTshjTyxnResult.getEjyy());
                    params.put(dataTshjTyxnResult.getYyzh() + "号最大差值", dataTshjTyxnResult.getChaMax());
                }
                params.put("时间油压曲线", new PictureRenderData(picW, picH, StringUtils.replace(dataTshjTyxnResults.get(0).getSjyyImg(), "/profile/chartPath", imgPath)));
                params.put("电流电压油压曲线", new PictureRenderData(picW, picH, StringUtils.replace(dataTshjTyxnResults.get(0).getDldyyyImg(), "/profile/chartPath", imgPath)));
            }
            //温升数据
            if (null != dataTshjWshResults && !dataTshjWshResults.isEmpty()) {
                params.put("1号冷却温度", dataTshjWshResults.get(0).getLqwd1());
                params.put("2号冷却温度", dataTshjWshResults.get(0).getLqwd1());
                params.put("1号工作温度", dataTshjWshResults.get(0).getGzwd1());
                params.put("2号工作温度", dataTshjWshResults.get(0).getGzwd2());
                params.put("1号温升", dataTshjWshResults.get(0).getWsh1());
                params.put("2号温升", dataTshjWshResults.get(0).getWsh2());
                params.put("温升曲线", new PictureRenderData(picW, picH, StringUtils.replace(dataTshjWshResults.get(0).getWshImg(), "/profile/chartPath", imgPath)));
            }
            //  油压数据
            if (null != dataTshjYyResults && !dataTshjYyResults.isEmpty()) {
                dataTshjYyResults.forEach(item -> {
                    //1号液压站
                    if(StringUtils.equals("1", item.getYyzh())) {
                        params.put("1号贴闸油压", item.getTzhyy());
                        params.put("1号松闸油压", item.getSzhyy());
                        params.put("1号残压", item.getCanya());
                        params.put("1号闸瓦正压力", item.getZhwzhyl());
                        params.put("1号制动力", item.getZhdl());
                        params.put("1号制动与松闸之差", item.getZhdszhcha());
                        params.put("1号闸电流", item.getZhdl());
                        params.put("1号贴闸时间", item.getTzhTime());
                        params.put("1号油压曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getYyImg(), "/profile/chartPath", imgPath)));
                    }
                    //2号液压站
                    if(StringUtils.equals("2", item.getYyzh())) {
                        params.put("2号贴闸油压", item.getTzhyy());
                        params.put("2号松闸油压", item.getSzhyy());
                        params.put("2号残压", item.getCanya());
                        params.put("2号闸瓦正压力", item.getZhwzhyl());
                        params.put("2号制动力", item.getZhdl());
                        params.put("2号制动与松闸之差", item.getZhdszhcha());
                        params.put("2号闸电流", item.getZhdl());
                        params.put("2号贴闸时间", item.getTzhTime());
                        params.put("2号油压曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getYyImg(), "/profile/chartPath", imgPath)));
                    }
                });
            }
            //制动数据
            if (null != dataTshjZhdResults && !dataTshjZhdResults.isEmpty()) {
                dataTshjZhdResults.forEach(item -> {
                    if(null != item.getUp() && null != item.getUpRen()) {
                        String type = DictUtils.getDictLabel("tshj_sd_up", item.getUp(), "") + DictUtils.getDictLabel("tshj_sd_upren", item.getUpRen(), "");
                        params.put(type + "制动时间", item.getZhdTime());
                        params.put(type + "制动距离", item.getZhdjl());
                        params.put(type + "制动初速度", item.getZhdchsd());
                        params.put(type + "制动减速度", item.getAccZhd());
                        params.put(type + "制动曲线", new PictureRenderData(picW, picH, StringUtils.replace(item.getZhdsdImg(), "/profile/chartPath", imgPath)));
                    }
                });
            }
            //制动力数据
            if(null != dataTshjZhdlResults && !dataTshjZhdlResults.isEmpty()) {
                params.put("制动拉力", df3.format((Float.valueOf(dataTshjZhdlResults.get(0).getZhdlj())/Float.valueOf(dataTshjZhdlResults.get(0).getZhdbj()))));
                params.put("制动力矩", dataTshjZhdlResults.get(0).getZhdlj());
            }
            //接触面积数据
            if(null != dataTshjJchmjResults && !dataTshjJchmjResults.isEmpty()) {
                dataTshjJchmjResults.forEach(item -> {
                    Map<String, Object> jchmjMap = new HashMap<>();
                    jchmjMap.put("时间", DateUtils.dateTime(item.getSaveTime()));
                    jchmjMap.put("接触面积", item.getJchmjVel());
                    jchmjList.add(jchmjMap);
                });
            }
            //拉压力数据
            if(null != dataTshjLylResults && !dataTshjLylResults.isEmpty()) {
                dataTshjLylResults.forEach(item -> {
                    Map<String, Object> lylMap = new HashMap<>();
                    lylMap.put("时间", DateUtils.dateTime(item.getSaveTime()));
                    lylMap.put("拉压力", item.getLylVel());
                    lylList.add(lylMap);
                });
            }
            //振动数据
            if(null != dataTshjZhdoResults && !dataTshjZhdoResults.isEmpty()) {
                dataTshjZhdoResults.forEach(item -> {
                    Map<String, Object> zhdoMap = new HashMap<>();
                    zhdoMap.put("时间", DateUtils.dateTime(item.getSaveTime()));
                    zhdoMap.put("振动", item.getZhdoVel());
                    zhdoList.add(zhdoMap);
                });
            }
            //照度数据
            if(null != dataTshjZhduResults && !dataTshjZhduResults.isEmpty()) {
                dataTshjZhduResults.forEach(item -> {
                    Map<String, Object> zhduMap = new HashMap<>();
                    zhduMap.put("时间", DateUtils.dateTime(item.getSaveTime()));
                    zhduMap.put("照度", item.getZhdVel());
                    zhduList.add(zhduMap);
                });
            }
            //噪声数据
            if(null != dataTshjZshResults && !dataTshjZshResults.isEmpty()) {
                dataTshjZshResults.forEach(item -> {
                    Map<String, Object> zshMap = new HashMap<>();
                    zshMap.put("时间", DateUtils.dateTime(item.getSaveTime()));
                    zshMap.put("噪声", item.getZshVel());
                    zshList.add(zshMap);
                });
            }
            //list结果传到map
            params.put("接触面积测试数据List", jchmjList);
            params.put("拉压力测试数据List", lylList);
            params.put("振动测试数据List", zhdoList);
            params.put("照度测试数据List", zhduList);
            params.put("噪声测试数据List", zshList);
            String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
            String docFileName = System.currentTimeMillis() + "-tshj.docx";
            //如果模板为空读取本地模板
            boolean isOk;
            if(StringUtils.isNotEmpty(template)) {
                isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
            }else {
                String currentPath = System.getProperty("user.dir");
                //父级路径
                String parentPath = new File(currentPath).getParent();
                System.out.println(currentPath);
                isOk = ExportWordUtils.exportWord( currentPath + "/tshj.docx", docRootPath, docFileName, params);
            }
            System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
            if(isOk) {
                return "/profile/document/" + docFileName;
            }else {
                return "";
            }
        }
        return "";
    }


}
